package org.icop.virtdoc;

import java.util.Collection;
import java.util.Map;

import org.jbpt.graph.abs.IEdge;
import org.jbpt.graph.abs.IGraph;
import org.jbpt.hypergraph.abs.IVertex;

/**
 * This class represents a virtual doc for single vertex, such that
 * the neighbors of the vertex are taken into account.
 *
 */
public class ContextVirtualDoc<G extends IGraph<E,V>, E extends IEdge<V>, V extends IVertex> extends StandardVirtualDoc<G, E, V> implements VirtualDoc {
	
	public ContextVirtualDoc(G graph, Collection<V> vertices, Map<V, Map<String, String>> attributes) {
		super(graph,vertices, attributes);
	}

	@Override
	protected void initDocForAllVertices(G g, Collection<V> vertices, Map<V, Map<String, String>> attributes) {
		super.initDocForAllVertices(g, vertices, attributes);
		
		/*
		 * consider also the neighbors of all nodes
		 */
		for (V v : vertices) {
			for (V n : g.getAdjacent(v)) {
				if (v.equals(n))
					continue;
				super.initDocForSingleVertex(g, n, attributes.get(v));
			}
		}
	}

	@Override
	protected void increaseTermWeight(int index, String attribute) {
		this.termWeights.set(index, this.termWeights.get(index) + VirtualDocParams.neighborWeightFactor * VirtualDocParams.getAttributeWeight(attribute));
	}
}
